<template>
  <el-dialog
    class="gl_dialog_TitleLine"
    width="1000px"
    title="计算记录"
    :visible.sync="detailDialogVisible"
    :close-on-click-modal="false"
    :close-on-press-escape="false"
    append-to-body
  >
    <el-row class="gl_mb_5">
      <el-col align="right">
        <el-button type="text" @click="getData()">刷新</el-button>
      </el-col>
    </el-row>
    <el-table v-loading="loading" class="gl_mb_15 game_table_list" :data="detailData" stripe size="mini" style="width: 100%">
      <el-table-column type="index" label="序号" align="center" width="50" />
      <el-table-column prop="name" label="计算表单" />
      <el-table-column prop="actualStartTime" label="开始时间" width="150" align="center">
        <template slot-scope="{ row }">
          <span v-if="!row.actualStartTime || row.actualStartTime == '0001-01-01T00:00:00'">- -</span>
          <span v-else>{{ row.actualStartTime | FormatDate('yyyy-MM-dd HH:mm') }}</span>
        </template>
      </el-table-column>
      <el-table-column prop="completedTime" label="结束时间" width="150" align="center">
        <template slot-scope="{ row }">
          <span v-if="!row.completedTime || row.completedTime == '0001-01-01T00:00:00'">- -</span>
          <span v-else>{{ row.completedTime | FormatDate('yyyy-MM-dd HH:mm') }}</span>
        </template>
      </el-table-column>
      <el-table-column prop="elapsedTime" label="耗时" width="100">
        <template slot-scope="{ row }">
          <span v-if="!row.completedTime || row.completedTime == '0001-01-01T00:00:00'">- -</span>
          <span v-else>{{ row.elapsedTime || '- -' }}</span>
        </template>
      </el-table-column>
      <el-table-column prop="statusCode" label="状态" width="100" align="center">
        <template slot-scope="{ row }">
          <span>{{ row.taskStatus && row.taskStatus.name }}</span>
        </template>
      </el-table-column>
      <el-table-column prop="execResultCode" label="结果" width="100" align="center">
        <template slot-scope="{ row }">
          <div v-if="row.execResultCode == 'Success' || row.execResultCode == 'Failed' || row.execResultCode == 'Timeout'">
            <span v-if="row.execResultCode == 'Success'" class="gl_color_success">{{ row.taskExecResult && row.taskExecResult.name }}</span>
            <span v-if="row.execResultCode == 'Failed' || row.execResultCode == 'Timeout'" class="gl_color_error">{{ row.taskExecResult && row.taskExecResult.name }}</span>
          </div>
          <div v-else>- -</div>
        </template>
      </el-table-column>
    </el-table>

  </el-dialog>
</template>
<script>
import {
  api_GET_EventsManagementPointTaskDetailsTaskGroupId
} from '@/extend/api/game.js';
export default {
  data() {
    return {
      loading: false,
      detailData: [],
      detailDialogVisible: false
    };
  },
  methods: {
    open(taskGroupId) {
      this.taskGroupId = taskGroupId;
      this.getData();
      this.detailDialogVisible = true;
    },
    // 获取任务明细列表
    getData() {
      var that = this;
      that.loading = true;
      api_GET_EventsManagementPointTaskDetailsTaskGroupId(that.taskGroupId).then(res => {
        that.detailData = res || [];
        if (that.detailData.length > 0) {
          that.detailData = that.detailData.map(item => {
            let sTime = item.elapsedTime || 0;
            let hTime = 0;
            let mTime = 0;
            if (sTime >= 60) {
              mTime = parseInt(sTime / 60);
              sTime = parseInt(sTime % 60);
              if (mTime >= 60) {
                hTime = parseInt(mTime / 60);
                mTime = parseInt(mTime % 60);
              }
            }
            sTime = sTime ? sTime + '秒' : '';
            mTime = mTime ? mTime + '分' : '';
            hTime = hTime ? hTime + '时' : '';
            item.elapsedTime = hTime + mTime + sTime;
            return { ...item };
          });
        }
        that.loading = false;
      }, error => {
        that.loading = false;
        const _msg = error.error.message || error.message;
        that.$message({ type: 'error', message: _msg || '获取数据失败！' });
      });
    }
  }
};
</script>

